package com.sch.www.feign.fallback;


import com.sch.www.common.core.web.ResponseBean;
import com.sch.www.entity.*;
import com.sch.www.feign.UserApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 日志断路器实现
 *
 * @author tangyi
 * @date 2019/3/23 23:39
 */

public class UserApiFallbackImpl implements UserApi {

    private static final Logger logger = LoggerFactory.getLogger(UserApiFallbackImpl.class);

    private Throwable throwable;

    /**
     * 根据用户名查询用户信息
     *
     * @param username username
     * @return SysUser
     */
    @Override
    public SysUser findUserByUsername(String username) {
        logger.error("feign 查询用户信息失败:{},{}", username, throwable);
        return null;
    }

    /**
     * 查询当前登录的用户信息
     *
     * @return ResponseBean
     */
    @Override

    public ResponseBean<SysUser> info() {
        logger.error("feign 查询用户信息失败:{},{}", throwable);
        return null;
    }

    /**
     * 根据用户ID批量查询用户信息
     *
     * @param SysUser SysUser
     * @return ResponseBean
     */
    @Override
    public ResponseBean<List<SysUser>> findUserById(@RequestBody SysUser SysUser) {
        logger.error("调用{}异常:{},{}", "findById", SysUser, throwable);
        return null;
    }

    /**
     * 根据部门ID批量查询部门信息
     *
     * @param deptVo deptVo
     * @return ResponseBean
     */
    @Override
    public ResponseBean<List<SysDept>> findDeptById(@RequestBody SysDept deptVo) {
        logger.error("调用{}异常:{},{}", "findById", deptVo, throwable);
        return null;
    }

    /**
     * 根据附件ID删除附件
     *
     * @param id id
     * @return ResponseBean
     */
    @Override
    public ResponseBean<Boolean> deleteAttachment(String id) {
        logger.error("调用{}异常:{},{}", "delete", id, throwable);
        return new ResponseBean<>(Boolean.FALSE);
    }

    /**
     * 根据附件ID批量查询附件信息
     *
     * @param attachmentVo attachmentVo
     * @return ResponseBean
     */
    @Override
    public ResponseBean<List<SysAttachment>> findAttachmentById(SysAttachment attachmentVo) {
        logger.error("调用{}异常:{},{}", "findById", attachmentVo, throwable);
        return new ResponseBean<>(new ArrayList<>());
    }

    /**
     * 保存日志
     *
     * @param log log
     * @return ResponseBean
     */
    @Override
    public ResponseBean<Boolean> saveLog(SysLog log) {
        logger.error("feign 插入日志失败,{}", throwable);
        return null;
    }

    /**
     * 根据角色查找菜单
     *
     * @param role 角色
     * @return   List
     */
    @Override
    public List<SysMenu> findMenuByRole(String role) {
        logger.error("feign 获取角色菜单失败,{}", throwable);
        return new ArrayList<>();
    }

    public Throwable getThrowable() {
        return throwable;
    }

    public void setThrowable(Throwable throwable) {
        this.throwable = throwable;
    }
}
